# -*- coding:utf-8
'''
作者: Jia
日期: 2022年04月21日
描述: https://leetcode-cn.com/problems/check-if-it-is-a-straight-line/
'''

from typing import List


class Solution:
    def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
        coordinates.sort(key = lambda x : (x[0], x[1]))
        dx = coordinates[1][0] - coordinates[0][0]
        dy = coordinates[1][1] - coordinates[0][1]

        for i in range(len(coordinates) - 1):
            if dx == 0:
                if coordinates[i+1][0] - coordinates[i][0] != 0:
                    return False
                if coordinates[i+1][1] - coordinates[i][1] != dy:
                    return False
            elif dy == 0:
                if coordinates[i+1][1] - coordinates[i][1] != 0:
                    return False
                if coordinates[i+1][0] - coordinates[i][0] != dx:
                    return False
            elif coordinates[i+1][0] - coordinates[i][0] != dx or coordinates[i+1][1] - coordinates[i][1] != dy:
                return False
        return True